package com.tiancheng.trade.settlement.controller.admin;

import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.settlement.exception.BusinessException;
import com.tiancheng.trade.settlement.model.settlement.CouponBill;
import com.tiancheng.trade.settlement.service.settlement.ICouponBillService;
import com.tiancheng.trade.settlement.vo.settlement.admin.CouponBillQueryVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 优惠券报表
 *
 * @author dell
 */
@RestController
@RequestMapping("/admin/couponBill")
public class CouponsBillController {
    @Resource
    private ICouponBillService couponBillService;

    @GetMapping("/generate")
    public Result query(@RequestParam("date")String date) throws BusinessException {
        couponBillService.handleCouponBillData(date);
        return Result.success();
    }

    @PostMapping("/query")
    public Result query(@RequestBody CouponBillQueryVO queryVO) throws BusinessException {
        PageInfo<CouponBill> page= couponBillService.query(queryVO);
        return Result.success(page);
    }

    @PostMapping("/export")
    public Result export(@RequestBody CouponBillQueryVO queryVO, HttpServletRequest request, HttpServletResponse response) throws BusinessException, IOException, IllegalAccessException {
        return couponBillService.export(queryVO,request,response);
    }

}
